const isProduction = process.env.NODE_ENV === 'production' // 是否在正式环境
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const path = require('path')
const { output, devServer } = require('./src/micros/config')
function resolve (dir) {
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: process.env.VUE_APP_PUBLIC_PATH,
    productionSourceMap: false,
    css: {
        loaderOptions: {
            sass: {
                prependData: '@import "./src/assets/style/base.scss";'
            }
        },
        extract: true,
        sourceMap: false
    },

    // 微应用打包之后 css 中的字体文件和图片加载 404
    chainWebpack: (config) => {
        config.module.rule('fonts').use('url-loader').loader('url-loader').options({}).end()
        config.module.rule('images').use('url-loader').loader('url-loader').options({}).end()
    },

    configureWebpack: config => {
        Object.assign(config.output, output)
        isProduction && config.plugins.push(
            new CompressionWebpackPlugin({
                algorithm: 'gzip',
                test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                threshold: 10240,
                minRatio: 0.8
            })
        )
        config.resolve.alias['@asset'] = resolve('src/assets')
        config.resolve.alias['@'] = resolve('src')
        config.resolve.alias._c = resolve('src/components')
    },
    devServer: {
        open: false,
        compress: true,
        overlay: {
            // 出现编译器错误或警告时，在浏览器中显示全屏覆盖层
            warnings: true,
            errors: true
        },
        port: 8081,
        ...devServer
    },
    transpileDependencies: ['eve-ui', 'element-ui']
}
